<?php
require_once(ROOT_ADMIN_OBJECT.DS.'Objs_Group_Privilege.php');
require_once(ROOT_ADMIN_MODELS.DS.'Models_Base.php');
class Models_Group_Privilege extends Models_Base{		    
    public function __construct(){
    	parent::__construct();
    	$this->_key="id";
    	$this->_table="group_privileges";
    }
	public function getGroupPrivilege($groupId, $privilegeId)
	{
		$sql = "SELECT
					*
				FROM
					group_privileges
				WHERE
					1";
		$sql.="	AND		group_id = '$groupId'";
		if($privilegeId != "")
			$sql.="			AND privilege_id = '$privilegeId'";
		
		$data = $this->_db->fetchRow($sql, null, Zend_Db::FETCH_OBJ);
		
		return $data;
	}
	
	public function getarrGroupPrivilege($groupId, $privilegeId)
	{
		$sql = "SELECT
					*
				FROM
					group_privileges
				WHERE
					1";
		if($groupId != "")
			$sql.="	AND		group_id = '$groupId'";
		if($privilegeId != "")
			$sql.="			AND privilege_id = '$privilegeId'";
	
		$data = $this->_db->fetchAll($sql, null, Zend_Db::FETCH_OBJ);
	
		return $data;
	}
	
	public function getarrControllname($groupId)
	{
		$sql = "SELECT DISTINCT 
					controllerName as privilege_id
				FROM 
					`privileges`,group_privileges
		 		WHERE 
					privileges.id = privilege_id ";
		if($groupId != "")
			$sql.="	AND		group_id = '$groupId'";
		
		$data = $this->_db->fetchAll($sql, null, Zend_Db::FETCH_OBJ);
	
		return $data;
	}
	
	public function deleteByGroup($id)
	{
		$sql = "DELETE FROM group_privileges WHERE group_id = $id";
		$this->_db->query($sql);
	}
}
	